<template>
  <div class="left-menu">
    <ul>
      <li v-for="(menu, index) in menuStore" :key="index" :data-index="menu.index">
        <router-link :to="{ path: '/'+ menu.url + '/'+ index  }">

          <div class="text-center">
            <div class="searchBtn">
              <svg class="icon">
                <use :xlink:href="'#' + menu.icon "></use>
              </svg>
            </div>
            <span>{{ menu.menuname }}</span>
          </div>
        </router-link>
      </li>
    </ul>
  </div>
</template>

<script>
import { mapState } from 'vuex'
export default {
  computed: {
    ...mapState({
      menuStore: state => state.menuStore.menus
    })
  }, 
  watch: {
    '$route' (to, from) {
      let toindex =  to.params.pathindex;
      let fromindex =  from.params.pathindex;

      if(fromindex < toindex){
        this.$emit('s2b', true);

      }else{
        this.$emit('s2b', false);
      }

    }
  } 
}
</script>
<style lang="scss" scoped>
.icon {
  display: block;
  width: 20px;
  height: 20px;
  fill: currentColor;
  overflow: hidden;
}
.searchBtn {
  margin: 0 auto;
  cursor: pointer;
  color: #a8b8d0;
  padding: 5px;
  border-radius: 50%;
}
.text-center {
  text-align: center;
}
.left-menu {
  position: absolute;
  width: 3.75rem;
  height: calc(100vh - 40px);
  ul {
    position: absolute;
    top: 0;
    left: 0;
    top: 2.375rem;
    height: 100%;
    background: #2b2a33;
    box-shadow: 2px 0 5px rgba(0, 0, 0, 0.2);
    li {
      position: relative;
      width: 3.75rem;
      height: 20%;
      font-size: 0.875rem;
      vertical-align: middle;
      z-index: 2;
      color: #a8b8d0;
      a {
        position: relative;
        display: flex;
        align-items: center;
        justify-content: center;
        width: 100%;
        height: 100%;
        color: #a8b8d0;
        &.active {
          color: #fff;
          &:before {
            position: absolute;
            left: 0;
            top: 10%;
            height: 80%;
            width: 0.1875rem;
            background: #7873f8;
            content: "";
          }
          .searchBtn {
            color: #fff;
            background: #776efd;
            padding: 10px;
          }
        }
      }
    }
  }
}
.name-time span {
  font-size: 14px;
}
</style>